﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

/// <summary>
/// Summary description for ImageBusiness
/// </summary>
public class ImageBusiness
{
    ImageData image = new ImageData();
	public ImageBusiness()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    public bool add(ImageEntities item)
    {
        return image.add(item);
    }
    public bool edit(ImageEntities item)
    {
        return image.edit(item);
    }
    public bool delete(int id)
    {
        return image.delete(id);
    }
    private System.Collections.ArrayList Items(DataTable dt)
    {
        System.Collections.ArrayList items = new System.Collections.ArrayList();
        if (dt != null)
        {
            ImageEntities item = null;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow row = dt.Rows[i];
                item = new ImageEntities();
                item._id = int.Parse(row["id"].ToString().Trim());
                item._url = row["url"].ToString();
                item._link = row["link"].ToString();
                item._alt = row["alt"].ToString();
                item._width = row["width"].ToString();
                item._height = row["height"].ToString();
                item._author = row["author"].ToString();
                items.Add(item);
                item = null;
            }
        }
        return items;
    }
    public System.Collections.ArrayList getImage()
    {
        DataTable dt = image.getImage(0);
        return this.Items(dt);
    }

    public ImageEntities getItem(int id)
    {
        ImageEntities item = new ImageEntities();
        if (id > 0)
        {
            DataTable dt = image.getImage(id);
            if (dt != null && dt.Rows.Count > 0)
            {
                DataRow row = dt.Rows[0];
                item._id = int.Parse(row["id"].ToString().Trim());
                item._url = row["url"].ToString();
                item._link = row["link"].ToString();
                item._alt = row["alt"].ToString();
                item._width = row["width"].ToString();
                item._height = row["height"].ToString();
                item._author = row["author"].ToString();
            }
        }
        return item;
    }

    public System.Collections.ArrayList getPanel_Image(int panel_id)
    {
        if (panel_id > 0)
        {
            DataTable dt = image.getPanel_Image(panel_id);
            return this.Items(dt);
        }
        else
        {
            return this.getImage();
        }
    }
}
